package com.yao.component.circle;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.hzl.UserInfoBean;
import com.yzf.bean.GroupBean;

import java.io.Serializable;
import java.util.ArrayList;

public class VisibleFriendActivity extends Activity {

    private ArrayList<GroupBean> goupList;
    private ListView friendList;
    private ArrayList<VisibleFriendBean> list = new ArrayList<VisibleFriendBean>();
    private MyAdapter myAdapter;
    private ArrayList<UserInfoBean> remindList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_visible_friend);
        Intent intent = getIntent();
        goupList = (ArrayList<GroupBean>) intent.getSerializableExtra("goupList");
        remindList = (ArrayList<UserInfoBean>) intent.getSerializableExtra("remindList");
        for (int i = 0; i < remindList.size(); i++) {
            UserInfoBean userInfoBean = remindList.get(i);
            list.add(new VisibleFriendBean(userInfoBean.getHeadImg(),userInfoBean.getUserName()));
        }
        for (int i = 0; i < goupList.size(); i++) {
            ArrayList<UserInfoBean> personList = goupList.get(i).getPersonList();
            for (int j = 0; j < personList.size(); j++) {
                UserInfoBean userInfoBean = personList.get(j);
                list.add(new VisibleFriendBean(userInfoBean.getHeadImg(),userInfoBean.getUserName()));
            }
        }
        friendList = (ListView) findViewById(R.id.friendList);
        myAdapter = new MyAdapter();
        friendList.setAdapter(myAdapter);
        findViewById(R.id.tv_left).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    class ViewHolder{
        ImageView img_head;
        TextView tv_name;
    }

    class MyAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View inflate = null;
            ViewHolder holder = null;
            if (convertView == null){
                holder = new ViewHolder();
                inflate = getLayoutInflater().inflate(R.layout.friend_item, null);
                holder.img_head = (ImageView) inflate.findViewById(R.id.img_head);
                holder.tv_name = (TextView) inflate.findViewById(R.id.tv_name);
                inflate.setTag(holder);
            }else {
                inflate = convertView;
                holder = (ViewHolder) inflate.getTag();
            }
            VisibleFriendBean visibleFriendBean = list.get(position);
            holder.img_head.setImageResource(visibleFriendBean.getHeadimg());
            holder.tv_name.setText(visibleFriendBean.getName());
            return inflate;
        }
    }

}
